#include "Organization.h"
/*
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Security ip="10.10.108.129" date="1365580205000" digitalseal="2e0d1b3826449b75110736bee07427d9"/>
<Service business="AAS" function="getMonitorCenterList"/>	
<RequestInfo querytype="List" page="" pagesize="">		
<GetMonitorCenterInfo uid="root" token="4a2925d9a21219da053023b4d347f8c5" mcflag="001"/>	
</RequestInfo>
</Request>
*/
/*
<?xml version="1.0" encoding="UTF-8"?>
<Result><ResultInfo resultcode="200" errormessage="OK"/>
<Service business="AAS" function="getMonitorCenterList"/>
<ResultData querytype="List">
<MonitorCenter id="1" name="" mcflag="001" parentid="0" type="0"/>
<MonitorCenter id="33" name="NS" mcflag="001001" parentid="1" type="0"/>
<MonitorCenter id="35" name="BH" mcflag="001001001" parentid="33" type="0"/>
<MonitorCenter id="34" name="SK" mcflag="001002" parentid="1" type="0"/>
</ResultData>
</Result>
*/

OrgReqReader::OrgReqReader(void)
{
}


OrgReqReader::~OrgReqReader(void)
{
}

int OrgReqReader::read(CommRequest& userLogin)
{
	OrgReq& orgReq = static_cast<OrgReq&>(userLogin);
	TiXmlElement* pChild = m_pRootEle->FirstChildElement("RequestInfo");
	const char* strType = pChild->Attribute("querytype");
	TiXmlElement* pChild2 = pChild->FirstChildElement("GetMonitorCenterInfo");
	orgReq.uid = pChild2->Attribute("uid");
	orgReq.token = pChild2->Attribute("token");
	orgReq.mcflag = pChild2->Attribute("mcflag");

	return 0;
}

OrgRepWriter::OrgRepWriter(void)
{
}


OrgRepWriter::~OrgRepWriter(void)
{
}
int OrgRepWriter::doWrite(const CommReply& rep,string& reply)
{
	const OrgRep& orgRep = static_cast<const OrgRep&>(rep);

	TiXmlElement ResultInfoEle("ResultInfo");
	ResultInfoEle.SetAttribute("resultcode",orgRep.status);
	ResultInfoEle.SetAttribute("errormessage","OK");

	m_pRootNode->InsertEndChild(ResultInfoEle);

	TiXmlElement ServiceEle("Service");
	ServiceEle.SetAttribute("business","AAS");
	ServiceEle.SetAttribute("function","getMonitorCenterList");
	m_pRootNode->InsertEndChild(ServiceEle);

	TiXmlElement ResultDataEle("ResultData");
	ResultDataEle.SetAttribute("querytype","list");

	TiXmlNode* pResultDataNode = m_pRootNode->InsertEndChild(ResultDataEle);

	int size = orgRep.vecOrg.size();
	for (int i=0;i<size;i++)
	{
		TiXmlElement orgEle("MonitorCenter");
		orgEle.SetAttribute("id",orgRep.vecOrg[i].id);
		orgEle.SetAttribute("name",orgRep.vecOrg[i].name);
		orgEle.SetAttribute("mcflag",orgRep.vecOrg[i].mcflag);
		orgEle.SetAttribute("parentid",orgRep.vecOrg[i].parentid);
		orgEle.SetAttribute("type",orgRep.vecOrg[i].type);

		TiXmlNode* pAuthNode = pResultDataNode->InsertEndChild(orgEle);
	}

	reply << *m_pDoc;

	return 0;
}
